import { createApp, type Directive, type ObjectDirective } from "vue";
import { createPinia } from "pinia";

import ElementPlus, { ElMessage } from "element-plus";
import "element-plus/dist/index.css";

// import "primevue/resources/primevue.min.css";
//theme
// import "primevue/resources/themes/saga-blue/theme.css";
// icon
// import "primeicons/primeicons.css";
// flex
// import "primeflex/primeflex.min.css";
import Toast, { TYPE, POSITION } from "vue-toastification";
import 'vue-toastification/dist/index.css'
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
import App from "./App.vue";
import router from "./router";
import { primeVuePlugins, primevueDirective } from "./utils/primevue";
import "./assets/main.less";
import { keys } from "lodash";

const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);

const app = createApp(App);

app.use(router);
app.use(pinia);
app.use(ElementPlus);

// 注册插件
primeVuePlugins.forEach((plugin) => {
  app.use(plugin);
});

// 注册指令
keys(primevueDirective).forEach((directive: string) => {
  // @ts-ignore
  const d =  primevueDirective[directive]
  app.directive(directive, d)
})

const options = {
  toastDefaults: {
    // ToastOptions object for each type of toast
    [TYPE.ERROR]: {
      timeout: 10000,
      closeButton: false,
    },
    [TYPE.SUCCESS]: {
      timeout: 3000,
      hideProgressBar: false,
      position: POSITION.TOP_CENTER
    },
  },
};
const T = Toast
app.use(T, options);

app.mount("#app");
